package com.googlecode.wcbunittests.test.matchers;

import org.apache.commons.lang.StringUtils;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;

/**
 * A simple typesafe Hamcrest matcher that asserts a String object contains only the indicated
 * characters. Uses Apache Commons Lang StringUtils internally.
 * 
 * @since v. 1.0.0
 * @author Freek Wielstra
 *
 */
public class ContainsOnly extends TypeSafeMatcher<String> {

    private final String permittedCharacters;
    
    public ContainsOnly(String permittedCharacters) {
        this.permittedCharacters = permittedCharacters;
    }
    
    public void describeTo(Description description) {
       description.appendText("does not contain only ").appendValue(permittedCharacters);
    }

    @Override
    public boolean matchesSafely(String str) {
        return StringUtils.containsOnly(str, permittedCharacters);
    }

}
